 <!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			#msg{
				margin: 50px;
				font-size: 50px;
			}
			.btnstyle{
				margin: 0 0 0 60px;
			}
		</style>
	</head>
	<body>
		<div id="msg">0</div>
		<div class="btnstyle">
		<button id="btnStart" onclick="start();">开始计时</button>
		<button id="btnStop" onclick="stop();">结束计时</button>
		</div>
	</body>
	<script>
		var timer;
		var clickStart=0;
		function start(){
			clickStart++;//第一次点击时执行++，点击次数计时器
			var btnStart =document.getElementById("btnStart");//获得对象
			btnStart.innerText="暂停计时";
			if(clickStart%2!=0){
			var msg=document.getElementById("msg");
			timer=setInterval(function(){
			msg.innerText++;
			},100);
			}else{
				clearInterval(timer);
				clickStart=0;
				btnStart.innerText="开始计时";
			}
		}
		function stop(){
			clearInterval(timer);
			var btnStart =document.getElementById("btnStart");
			btnStart.innerText="开始计时";
			var msg=document.getElementById("msg");
			msg.innerText=0;
		}
	</script>
</html>
